function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

var openid=$.cookie('openid');
if(openid == null){
	var userInfo=$.ajax({url:"getUserInfo?code="+GetQueryString("code"),async:false,dataType:"json"}).responseJSON;
	$.cookie('nickname',userInfo["nickname"]);
	$.cookie('openid',userInfo["openid"]);
	$.cookie('headimgurl',userInfo["headimgurl"]);
}
$(function(){
	$("#WX").val($.cookie('nickname'));
	$("#wxid").val($.cookie('openid'));
	$("#WX").css("background","url("+$.cookie('headimgurl')+") no-repeat 16px center");	
	$("#WX").css("background-size","24px 24px");	
});
